#pragma once

#include <ros/ros.h>
#include <sensor_msgs/Image.h>
#include <sensor_msgs/CameraInfo.h>
#include <image_transport/image_transport.h>
#include <image_transport/camera_publisher.h>

#include <nlohmann/json.hpp>

#include "websocket/control_sdk.hpp"
#include "core/camera_common.hpp"
#include "decoder/frame_decoder.hpp"

namespace WD{   
class StarlightCamera
{
public:
    StarlightCamera(ros::NodeHandle& nh, ros::NodeHandle& nh_private);
    ~StarlightCamera();
    void initRos();
    void initCamera();
    void runStream();

private:
    nlohmann::json yamlToJson();
    void publishFrame(const FrameWithTimestamp& msg, const image_transport::Publisher& pub);
    void registerStreamCallback(int camera_id, const image_transport::Publisher& pub);

private:
    ros::NodeHandle nh_;
    ros::NodeHandle nh_private_;

    //参数
    WD::ImageOutParams image_params_;
    WD::PpsConfigParams pps_params_;
    WD::GpsParams gps_params_;
    WD::IpConfigParams ip_params_;

    image_transport::ImageTransport it_;
    image_transport::Publisher pub_image_1_;
    image_transport::Publisher pub_image_2_;
    image_transport::Publisher pub_image_3_;
    image_transport::Publisher pub_image_4_;
    image_transport::Publisher pub_image_split_;

    std::atomic<bool> running_{true};
    ThreadSafeQueue<sensor_msgs::ImagePtr> image_split_queue_;
    std::thread image_split_pub_thread_;

    std::queue<cv::Mat> frame_queue_;
    std::mutex frame_mutex_;

    std::unique_ptr<WD::ControlSdk> control_sdk_ptr_;
    std::unique_ptr<WD::FrameDecoder> decoder_ptr_;

    // 是否启用图像拼接
    bool stitching_;
};


}// namespace WD